/* 
 * File:   EnvCell.cpp
 * Author: flai0014
 * 
 * Created on March 30, 2012, 11:51 AM
 */

#include "EnvCell.h"

EnvCell::EnvCell(){
    cellLock = false;
    container.clear();
    agentCount = 0;
}

EnvCell::EnvCell(const EnvCell& orig){
    container = orig.container;
    cellLock = false;
    agentCount = 0;
}

bool EnvCell::checkLock(){
    return cellLock;
}

void EnvCell::getLock(){
    cellLock = true;
}

void EnvCell::releaseLock(){
    cellLock = false;
}

bool EnvCell::addParticle(Particle * item){
    container.push_back(item);
}

Particle * EnvCell::removeParticle(){
    Particle* item = container.back();
    container.pop_back();
    return item;
}

EnvCell::~EnvCell(){
    Particle* tmp;
    while(!container.empty()){
        tmp = container.back();
        container.pop_back();//Deletes particles in the cell
        delete tmp;
    }
}

int EnvCell::countParticles(){
    int count = 0;
    for(unsigned int i = 0; i < container.size(); i++)
        count += container[i]->getNum();//Adds up each ID
    return count;
}

int EnvCell::numberOfParticles(){
    return (int)container.size();
}

bool EnvCell::hasAgent(){
    if(agentCount > 0)
        return true;
    else
        return false;
}

void EnvCell::agentCheckIn(){
    agentCount++;//This function started acting up for no good reason
                 // it would cause a segmentation error
}

void EnvCell::agentCheckOut(){
    agentCount--;
    if(agentCount < 0)
        cerr << "To many agents checked out of Cell: \n";
}
